import { Column, Entity, PrimaryGeneratedColumn, OneToMany } from 'typeorm';
import { PostsEntity } from '../posts/posts.entity';

@Entity('user')
export class UserEntity {
  @PrimaryGeneratedColumn()
  id: number;

  @Column({ length: 50, unique: true })
  username: string;

  @Column({ length: 50 })
  password: string;

  @Column({ length: 50, default: '' })
  email: string;

  @Column({ length: 50, default: '' })
  phone: string;

  @Column({ length: 50, default: '' })
  avatar: string;

  @Column({ type: 'timestamp', default: () => 'CURRENT_TIMESTAMP' })
  create_time: Date;

  @Column({ type: 'timestamp', default: () => 'CURRENT_TIMESTAMP' })
  update_time: Date;

  // 用户和文章的一对多关系
  @OneToMany(() => PostsEntity, (post) => post.user)
  posts: PostsEntity[];
}
